package com.yuxi.Dao.Impl;

import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.yuxi.Entity.PowerRole;
import com.yuxi.Entity.PrisonRole;
import com.yuxi.Request.Page;
;

@Repository
public class PowerRoleDaoImpl extends BaseDaoImpl<Serializable, Serializable> implements com.yuxi.Dao.PowerRoleDao {
	private Logger logger=LoggerFactory.getLogger(PowerRoleDaoImpl.class);
	public PowerRoleDaoImpl(){
		super(PowerRole.class);
	}
	@Override
	public PowerRole getPowerRole(Integer powerRoleId) {
		// TODO Auto-generated method stub
		return (PowerRole) super.get(powerRoleId);
	}

	@Override
	public PowerRole addPowerRole(PowerRole pRole) {
		// TODO Auto-generated method stub
		return (PowerRole) super.addAndReturn(pRole);
	}

	@Override
	public void deletePowerRole(PowerRole pRole) {
		// TODO Auto-generated method stub
		super.delete(pRole);
	}

	@Override
	public void modifly(PowerRole pRole) {
		// TODO Auto-generated method stub
		super.update(pRole);
	}
	@Override
	public Page<PowerRole> getPowerRoleAll(Page p) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public List<PowerRole> getPowerByRoleId(Integer roleId) {
		// TODO Auto-generated method stub
		List<PowerRole> powerRoles=super.find("from PowerRole where roleId=?", roleId);
		return powerRoles;
	}
	@Override
	public void deletePowerRoleByRoleId(Integer roleId) {
		// TODO Auto-generated method stub
		super.delete("delete  PowerRole where roleId=?", roleId);
	}
	@Override
	public PowerRole getUserRolePower(int userId) {	
		String str=" new com.yuxi.Entity.PowerRole(rolePower.id,rolePower.roleId,"
				+ "rolePower.prisonAreaInfoAdd,"
				+ " rolePower.prisonAreaInfoManage,"
				+ " rolePower.prisonAreaFirstCheck,rolePower.prisonAreaReCheck, rolePower.prisonAreaCheck,"
				+ " rolePower.prisonAreaInfoResearch, rolePower.prisonAreaTaskDispatch, "
				+ "rolePower.prisonAreaCurTaskDispatch, rolePower.prisonAreaTaskFinsh,"
				+ " rolePower.prisonAreaInfoComment,rolePower.prisonAreaInfoRated,"
				+ " rolePower.prisonInfoAdd, rolePower.prisonInfoManage, rolePower.prisonFirstCheck,"
				+ " rolePower.prisonReCheck, rolePower.prisonCheck, "
				+ "rolePower.prisonInfoResearch, rolePower.prisonTaskDispatch,"
				+ " rolePower.prisonCurTaskDispatch, rolePower.prisonTaskFinsh, rolePower.prisonInfoComment, rolePower.prisonInfoRated,"
				+ "rolePower.userManage,rolePower.deployment,rolePower.infoQuery,rolePower.queryCommernt,rolePower.queryEvaluate,rolePower.deleteInformation,rolePower.personalDetails)";
		List<PowerRole> rsp=(List<PowerRole>)super.find("select "+str+"from  PowerRole  rolePower,PowerUser  userPower where userPower.roleId=rolePower.roleId and userPower.userId=?", userId);
		//		List<PowerRole> rsp=(List<PowerRole>)super.find("select "+str+"from  PowerRole as p,PowerUser as pw where pw.roleId=p.roleId and pw.userId=?", userId);
		return rsp.get(0);
	}

}
